{include file="common/head"}
<head>
<title>系统设置</title>
<link    rel="stylesheet"    href="https://cdnjs.cloudflare.com/ajax/libs/jodit/3.24.2/jodit.es2018.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jodit/3.24.2/jodit.es2018.min.js"></script>    
</head>
<body style="">
    <div class=" p-3 my-3 " style="max-width: 800px;"  >
    <h2>系统设置  
      <a href="/index/xcxz"><button class="btn btn-primary"> 学车须知</button></a> 
      <a href="/index/agreement"><button class="btn btn-secondary">用户协议</button></a>
    </h2>
    <form name='form1' method="post" action="/index.php/admin/sys" enctype="multipart/form-data">
      <input type="hidden" name="id" value="{$sys.id}"/>
      <div class="mb-3 mt-3">
        <lable for="name" class="form-label">系统名称:</label>
        <input type="text" class="form-control" id="sys_name" name="sys_name" value="{$sys.sys_name}" placeholder="Goods name" />
      </div>
      <div class="mb-3 mt-3">
        <lable for="name2" class="form-label">版权信息(CopyRight):</label>
        <input type="text" class="form-control" id="copy_right" name="copy_right" value="{$sys.copy_right}" placeholder="Goods name" />
      </div>      
      <div class="mb-3">
        <label for="title" class="form-label">首页公告:</label>
        <textarea class="form-control" id="msg" name="msg" rows="3">{$sys.msg}</textarea>
      </div>

      <div class="mb-3">
        <label for="title" class="form-label">关于我们:</label>
        <textarea id="about_msg" name="about_msg">{$sys.about_msg}</textarea>
      </div>  
      <div class="mb-3">
        <label for="pop_img" class="form-label">小程序开屏图片:</label>
        <img src="{$sys.pop_img}" style="width:100px;" />
        <input type="file" id="pop_img" name="pop_img" style="border:1px solid;"  />
      </div>  

      <div class="mb-3">
        <label for="" class="form-label">小程序轮播图上传:</label><br/>
        <div class="">
          {if $sys.top_images[0]}
          {foreach $sys.top_images as $img}
            <div style="border:1px solid #ccc;display: inline-grid;text-align: right;margin-bottom:1px;">
                <span class="bi-x-lg img_remove" row_id="1" src="{$img}" title="删除图片"></span>
                <img class="goods_image" src="{$img}" style="height:40px;" />
            </div>
          {/foreach}{else}无图片
          {/if}
          <input id="file1" type="file"  name="file1" style="display: none;" />
          <button id="img_add" type="button" class="btn btn-info" ><span class="bi-plus-lg"></span></button>
        </div>
      </div>

      <div class="mb-3" style="border:1px solid #ccc;">
          <label for="sign_up_sms" class="form-label">报名成功手机短信:</label>
          <input type="radio" class="form-check-input" id="radio1" name="sign_up_sms" value="1" {if $sys.sign_up_sms==1} checked {/if} /> 
          <label class="form-check-label" for="radio1">开启发送</label>
          <input type="radio" class="form-check-input" id="radio2" name="sign_up_sms" value="0" {if $sys.sign_up_sms!=1} checked {/if} />
          <label class="form-check-label" for="radio2">关闭</label>          
      </div>

      <button  type="button" class="btn btn-primary" onclick="doSave()">保存(Save)</button>

    </form>
    <hr/>


    <form action="" method="post" >
        <h2>平台佣金设定</h2>        
        <table class="table-sm table-hover"  class="form-control">
            <tr>
                <td>
                    <input type="number" class="form-control" min="0.05" max="0.5" step="0.05" id="commision" name="commision" value="{$sys.commision}" />
                </td>
                <td>
                    <button type="button" id="commision_save" class="btn btn-primary">保存设置</button>
                </td>
                <td>说明：平台佣金5%-50%之间。  </td>
            </tr>
        </table>
    </form>

    <script type="text/javascript">
        $("#commision_save").on('click',function(){
            var val = $("#commision").val();
            if(isNaN(val) || val<0.05 || val>0.5 ){
                layer.msg('佣金设置不正确,请设置0.05-0.5(5%-50%)');
                return false;
            }
            $.post('/sys/commision_set',{commision:val},function(res){
                console.log(res.code)
                layer.msg(res.msg);
            })

        });    
        
    </script>

    
    </div>

<script type="text/javascript">
    var editor = Jodit.make('#about_msg',{
      toolbarButtonSize: 'small',
    });
    // var editor = Jodit.make('#msg',{
    //   toolbarButtonSize: 'small',
    // });
    //editor.value = ''; 

    function doSave(){
      if(!$("#sys_name").val()) {
        layer.msg("无效的名称(Invalid name)!");
        return 0;
      }
      
      //询问框
      layer.confirm('是否确定保存设置?', {
        btn: ['YES','CANCEL'] //按钮
      }, function(){
        $('form[name="form1"]').submit();
      }, function(){
        layer.msg("Cancel!");
        return 0;
      });
    }



  $(document).ready(function(){

    $(".goods_image").on('click',function(){
        var img = $(this).attr('src');
        if(!img.trim()) return;

        layer.open({
          type: 1,
          title:'',
          closeBtn: 0, //不显示关闭按钮
         // anim: 1,
          time: 5*1000,
          shadeClose: true, //开启遮罩关闭              
          skin: 'layui-layer-rim', 
          content: "<img src='"+img+"' style='width:100%'>"
        });
    })


    $(".img_remove").on('click',function(){
      var src=$(this).attr('src');
      var row_id=$(this).attr('row_id');

      //询问框
      layer.confirm('是否确定删除图片?', {
        btn: ['确定','取消'] //按钮
      }, function(){
        
        $.post('/index.php/sys/img_remove',{tb:'sys',row_id:1,field:'top_images',src:src},function(res){
            if(res.code){
                layer.msg(res.msg);
                location.reload();
            }
            
        })

      }, function(){
        layer.msg("好的!");
        return 0;
      });
    })

    $('#img_add').on('click',function(){$('#file1').click()})
    //提交图片
    $("#file1").on('change',function(e){
      var el1='<input name="tb"  type="hidden" value="sys+top_images" />';
      var el2='<input name="source_url" type="hidden" value="/admin/sys" />';
      $('#file1').after(el1).after(el2);

      $('form[name="form1"]').attr('action','/sys/img_add').submit();
    })

  })  
</script>


</body>
</html>
